//
//  RecomOrderViewController.m
//  XWZ_News_Work
//
//  Created by dllo on 16/1/18.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "RecomOrderViewController.h"
#import "tempTwoTableViewCell.h"
#import "orderModel.h"
#import "OrderDetailViewController.h"

#define URL @"http://c.3g.163.com/nc/topicset/subscribe/recommend.html"

@interface RecomOrderViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableV;
@property (nonatomic, strong) NSMutableArray *myDataArr;

@end

@implementation RecomOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    self.title = @"精选订阅";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhui"] style:(UIBarButtonItemStylePlain) target:self action:@selector(returnAction)];
    [self createTableView];
    [self createData];
}

- (void)createData
{
    [xwzAFNetTool getNetWithURL:URL body:nil headFile:nil responStyle:XWZ_JSON success:^(NSURLSessionDataTask *task, id responseObject) {
       
        NSMutableArray *arr = [responseObject objectForKey:@"recommendlist"];
        self.myDataArr = [orderModel baseModeWithArr:arr];
        if (self.myDataArr) {
            [self.tableV reloadData];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}

- (void)createTableView
{
    self.tableV.separatorStyle = NO;
    self.tableV = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    [self.view addSubview:self.tableV];
    [self.tableV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.equalTo(self.view);
        
    }];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 4;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 4;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.myDataArr.count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 150;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    orderModel *model = [self.myDataArr objectAtIndex:indexPath.section];
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    OrderDetailViewController *orderVc = [[OrderDetailViewController alloc] init];
    orderVc.code = model.tid;
    orderVc.myTitle = model.title;
    orderVc.alias = model.alias;
    orderVc.source = model.tname;
    self.navigationController.navigationBarHidden = YES;
    [self.navigationController pushViewController:orderVc animated:YES];
    self.navigationController.navigationBarHidden = NO;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    orderModel *model = [self.myDataArr objectAtIndex:indexPath.section];
    static NSString *cellStr = @"cell";
    tempTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (nil == cell) {
        cell = [[tempTwoTableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellStr];
    }
    cell.myModel = model;
    return cell;
}

- (void)returnAction
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"showView" object:nil];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
